#ifndef MEANIC_H
#define MEANIC_H

#include "IndexCalculator.h"

class MeanIC : public IndexCalculator<double, double>
{
private:
    double sum;

public:
    explicit MeanIC(int period) : IndexCalculator<double, double>(period), sum(0.0) {}

    void calculate(const double &new_data) override
    {
        if (this->data_count <= this->period)
        {
            sum += new_data;
            this->result = sum / data_count;
        }
        else
        {
            sum += new_data - this->data[0];
            this->result = sum / period;
        }
    }

    void reset() override
    {
        IndexCalculator<double, double>::reset();
        sum = 0.0;
    }
};

#endif // MEANIC_H